'use strict';

module.exports = {
  up: async (queryInterface, Sequelize) => {
    const { INTEGER, STRING, DATE, ENUM } = Sequelize;
    
    await queryInterface.createTable('users', {
      id: {
        type: INTEGER,
        primaryKey: true,
        autoIncrement: true
      },
      name: {
        type: STRING(50),
        allowNull: false,
        comment: '用户姓名'
      },
      email: {
        type: STRING(100),
        allowNull: false,
        unique: true,
        comment: '邮箱'
      },
      password: {
        type: STRING(100),
        allowNull: false,
        comment: '密码'
      },
      role: {
        type: ENUM('admin', 'user', 'auditor'),
        allowNull: false,
        defaultValue: 'user',
        comment: '角色'
      },
      status: {
        type: ENUM('active', 'inactive', 'locked'),
        allowNull: false,
        defaultValue: 'active',
        comment: '状态'
      },
      last_login_at: {
        type: DATE,
        allowNull: true,
        comment: '最后登录时间'
      },
      created_at: {
        type: DATE,
        allowNull: false,
        defaultValue: Sequelize.NOW
      },
      updated_at: {
        type: DATE,
        allowNull: false,
        defaultValue: Sequelize.NOW
      }
    });
  },

  down: async (queryInterface, Sequelize) => {
    await queryInterface.dropTable('users');
  }
};